<template>
	<view class="askList">
		<navBar isBack title="大家都在问" backColor="#333" color="#333" background="#fff"></navBar>
		<view class="list">
			<view class="item" v-for="(item,index) in askList" :key="index">
				<view class="Q">
					<span>问</span>
					{{item.title}}
				</view>
				<view class="A" v-if="item.answer.length >0">
					<view class="userInfo">
						<image :src="item.answer[0].user_id.avatar.path" mode=""></image>
						{{item.answer[0].user_id.username}}
					</view>
					{{item.answer[0].content}}
				</view>
				<view class="time">
					{{$utils.getFormatDate(item.create_time*1000,'yyyy-MM-dd')}}
					<view class="all" @click="toQuestDetail(item.id)">
						<span>{{item.answer_num}}</span>个回答
					</view>
				</view>
			</view>
		</view>
		
		<!-- 我要提问 -->
		<view class="btnBox">
			<button class="btn" @click="toPutQuest">
				<u-icon name="edit-pen-fill"></u-icon>
				我要提问
			</button>
		</view>
	</view>
</template>

<script>
	import service_oneN from '@/service/oneN.js'
	export default{
		data(){
			return{
				estate_id:null,
				page:1,
				pagesize:10,
				askList:[],
			}
		},
		onLoad(options) {
			this.$utils.getUrl()
			this.estate_id = options.estate_id
			this.getAskListAll()
		},
		onShow() {
			this.getAskListAll()
		},
		onReachBottom() {
			this.page++;
			uni.showLoading({
				title:'加载中...'
			})
			let params = {
				estate_id:this.estate_id,
				page:this.page,
				pagesize:this.pagesize
			}
			service_oneN.getAskListAll(params).then(res=>{
				console.log(res,'提问列表')
				if(res.code==1){
					if(!res.data.length){
						uni.showToast({
							title:'没有更多了~',
							icon:'none'
						})
					}
					this.askList = this.askList.concat(res.data)
				}
			})
			setTimeout(function(){
				uni.hideLoading()
			},500)
		},
		methods:{
			// 问答列表
			getAskListAll(){
				this.page = 1
				let params = {
					estate_id:this.estate_id,
					page:this.page,
					pagesize:this.pagesize
				}
				service_oneN.getAskListAll(params).then(res=>{
					console.log(res,'提问列表')
					if(res.code==1){
						this.askList = res.data?res.data:[]
					}
				})
			},
			toPutQuest(){
				uni.navigateTo({
					url:`putQuest?estate_id=${this.estate_id}`
				})
			},
			
			// 问题详情
			toQuestDetail(id){
				uni.navigateTo({
					url:`./questDetail?question_id=${id}&estate_id=${this.estate_id}`
				})
			}
		}
	}
</script>

<style lang="scss">
	page{height: 100%;}
	.askList{
		width: 100%;
		height: 100%;
		background-color: #fff;
		.list{
			padding: 0 32rpx;
			background-color: #fff;
			margin-bottom: 108rpx;
			padding-bottom: constant(safe-area-inset-bottom);///兼容 IOS<11.2/
			padding-bottom: env(safe-area-inset-bottom);///兼容 IOS>11.2/
			.item{
				border-bottom: 2rpx solid #F4F4F4;
				padding: 40rpx 0rpx;
				background-color: #fff;
				display: flex;
				flex-direction: column;
				.Q{
					display: flex;
					align-items: center;
					font: 500 28rpx/40rpx PingFang SC;
					margin-bottom: 28rpx;
					color: #333;
					span{
						text-align: center;
						margin-right: 12rpx;
						width: 32rpx;
						height: 32rpx;
						border-radius: 4rpx;
						color: #fff;
						font: 500 20rpx/32rpx PingFang SC;
						background-image:linear-gradient(180deg, #FFCC60 0%, #FA8D38 100%) ;
					}
				}
				.A{
					font: 400 24rpx/44rpx PingFang SC;
					color: #939393;
					.userInfo{
						display: flex;
						align-items: center;
						image{
							width: 56rpx;
							height: 56rpx;
							border-radius: 50%;
							margin-right: 16rpx;
						}
						margin-bottom: 16rpx;
						font: 400 22rpx/44rpx PingFang SC;
						color: #333;
					}
				}
				.time{
					margin-top: 18rpx;
					display: flex;
					justify-content: space-between;
					font: 400 22rpx/44rpx PingFangSC-Regular;
					color: #939393;
					span{
						font: 400 24rpx/44rpx PingFangSC-Medium;
						color: #333;
					}
				}
			}
		}
		
		// 我要提问
		.btnBox{
			width: 100%;
			height: 108rpx;
			background-color: #fff;
			position: fixed;
			bottom: 0;
			left: 0;
			height: calc(108rpx+ constant(safe-area-inset-bottom));///兼容 IOS<11.2/
			height: calc(108rpx + env(safe-area-inset-bottom));///兼容 IOS>11.2/
			padding-bottom: constant(safe-area-inset-bottom);///兼容 IOS<11.2/
			padding-bottom: env(safe-area-inset-bottom);///兼容 IOS>11.2/
			.btn{
				u-icon{
					margin-right: 16rpx;
				}
				margin: 10rpx auto ;
				width: 520rpx;
				height: 88rpx;
				background-color: #C3AB7C;
				border-radius: 44rpx;
				font: 600 32rpx/88rpx PingFang SC;
				color: #fff;
				display: flex;
				justify-content: center;
			}
		}
	}
</style>
